import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_circle_color_picker/flutter_circle_color_picker.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter 颜色模式'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  BlendMode _blendMode = BlendMode.color;

  Color _color = Colors.grey;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 8),
              child: Text("Flutter颜色叠加模式预览",style: TextStyle(fontSize: 18),),
            ),
            Image.asset(
              "assets/images/demo.png",
              width: 300,
              height: 200,
              color: _color,
              colorBlendMode: _blendMode,
            ),
            CircleColorPicker(
              initialColor: _color,
              onChanged: (color){
                setState(() {
                  _color = color;
                });
              },
              size: const Size(220, 220),
              strokeWidth: 4,
              thumbSize: 24,
            ),
            SizedBox(
              height: 180,
              width: 300,
              child: CupertinoPicker(
                children: [
                  for (var item in BlendMode.values) Text(item.toString()),
                ],
                itemExtent: 45,
                onSelectedItemChanged: (item) {
                  setState(() {
                    _blendMode = BlendMode.values[item];
                  });
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
